package com.applozic.mobicomkit.uiwidgets.conversation.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.applozic.mobicomkit.api.conversation.Message;
import com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper;
import com.applozic.mobicommons.commons.core.utils.DateUtils;
import com.applozic.mobicommons.commons.core.utils.Utils;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.ui.component.BaseRelativeLayout;

import java.util.Map;

import butterknife.BindView;

public class ApplozicCallView extends BaseRelativeLayout {
    @BindView(R.id.applozic_call_image_type)
    ImageView imageView;
    @BindView(R.id.applozic_call_status)
    TextView statusTextView;
    @BindView(R.id.applozic_call_duration)
    TextView durationTextView;
    @BindView(R.id.applozic_call_timing)
    TextView timeTextView;

    public ApplozicCallView(Context context) {
        super(context);
    }

    public ApplozicCallView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ApplozicCallView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(Context context, AttributeSet attrs, int defStyleAttr) {

    }

    @Override
    protected void initView(Context context) {
        setContentView(R.layout.applozic_call_layout);
    }

    @Override
    protected void load(Context context) {

    }

    public void setData(Message msg) {

        Map<String, String> metaData = msg.getMetadata();
        timeTextView.setText(DateUtils.getFormattedDate(msg.getCreatedAtTime()));
        statusTextView.setText(VideoCallNotificationHelper.getStatus(metaData));

        if (VideoCallNotificationHelper.isMissedCall(msg)) {
            imageView.setImageResource(R.drawable.ic_communication_call_missed);
        }

        if (!VideoCallNotificationHelper.isAudioCall(msg)) {
            imageView.setImageResource(R.drawable.ic_videocam_white_24px);
        }

        if (metaData.get(VideoCallNotificationHelper.MSG_TYPE).equals(VideoCallNotificationHelper.CALL_END)) {

            String duration = metaData.get(VideoCallNotificationHelper.CALL_DURATION);

            if (!TextUtils.isEmpty(duration)) {

                durationTextView.setVisibility(View.VISIBLE);
                duration = Utils.getTimeDurationInFormat(Long.parseLong(duration));
                durationTextView.setText(duration);
            }
        } else {
            durationTextView.setVisibility(View.GONE);
        }

    }
}
